public class OpportunityCloneExtensions {
    private final Opportunity o;
    
    public OpportunityCloneExtensions(ApexPages.StandardController stdController) {
        this.o = (Opportunity)stdController.getRecord();
    }
     public OpportunityCloneExtensions() {

    }
    
    // Code we will invoke on page load.
    public PageReference autoRun() {
 
        String theId = ApexPages.currentPage().getParameters().get('id');
 
        if (theId == null) {
            // Display the Visualforce page's content if no Id is passed over
            return null;
        }
        
        //standard clone functionality for all record types..
        string retURL = '/'+ theId + '/e?clone=1 '+ '&retURL=/' + theId;
        
        //except Advanced Ads Solutions record type, gets some default values
        for (Opportunity o:[select id, recordtype.name from Opportunity where id =:theId]) {
            if(o.recordtype.name == 'Advanced Ad Solutions'){
                //set default values for AAS record type
                string closeDate = ToString(Date.today()+ 30, 'MM/dd/yyyy');
                string stage = 'Proposal Requested by AE';
                string probability = '25' ; 
            
                retURL += '&opp11='+ stage +'&opp12=' + probability +'&opp9=' + closeDate;
            }        
            //all other record types ,default behaviour!
        }
        

       
        // Redirect the user back to the original page
        PageReference pageRef = new PageReference(retURL);
        pageRef.setRedirect(true);
        return pageRef;
 
    }
    
  public static String ToString(Date Value,String format)
  {
    /* string representation if a Date value with formatting */
    Datetime temp = Datetime.newInstance(Value.year(), Value.month(), Value.day());
    return temp.format(format);
  }
}